import Vue from 'vue'
import VueRouter from 'vue-router'
const Main = () => import('../views/main.vue')
const CategoryEdit = () => import('../views/main/CategoryEdit.vue')
const CategoryList = () => import('../views/main/CategoryList.vue')
const SubjectEdit = () => import('../views/main/SubjectEdit.vue')
const SubjectList = () => import('../views/main/SubjectList.vue')
const TestEdit = () => import('../views/main/TestEdit.vue')
const TestList = () => import('../views/main/TestList.vue')
const AdminUserEdit = () => import('../views/main/AdminUserEdit.vue')
const AdminUserList = () => import('../views/main/AdminUserList.vue')
const Login = () => import('../views/Login.vue')
const Student = () => import('../views/User/Student.vue')
const AnswerEdit = () => import('../views/User/AnswerEdit.vue')
const AnswerList = () => import('../views/User/AnswerList.vue')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
   },
  {
    path: '/login',
    component: Login,
    meta: {isPublic: true}
  },
 
  {
    path: '/main',
    name: 'Main',
    component: Main,
    children: [
      {
        path: '/categories/edit',
        component: CategoryEdit
      },
      {
        path: '/categories/edit/:id',
        component: CategoryEdit,
        props: true
      },
      {
        path: '/categories/list',
        component: CategoryList
      },
      {
        path: '/subjects/edit',
        component: SubjectEdit
      },
      {
        path: '/subjects/edit/:id',
        component: SubjectEdit,
        props: true
      },
      {
        path: '/subjects/list',
        component: SubjectList
      },
      {
        path: '/tests/edit',
        component: TestEdit
      },
      {
        path: '/tests/edit/:id',
        component: TestEdit,
        props: true
      },
      {
        path: '/tests/list',
        component: TestList
      },
      {
        path: '/adminUser/edit',
        component: AdminUserEdit
      },
      {
        path: '/adminUser/edit/:id',
        component: AdminUserEdit,
        props: true
      },
      {
        path: '/adminUser/list',
        component: AdminUserList
      },
      {
        path: '/answer/edit',
        component: AnswerEdit
      },
      {
        path: '/answer/edit/:id',
        component: AnswerEdit,
        props: true
      },
      {
        path: '/answer/list',
        component: AnswerList
      },
      {
        path: '/student/list',
        component: Student
      },
      // {
      //   path: '/stuMessage/list',
      //   component: StuMessage
      // },
      // {
      //   path: '/teacher/list',
      //   component: Teacher
      // },
      // {
      //   path: '/teaMessage/list',
      //   component: TeaMessage
      // },
      
    ]
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
if (!to.meta.isPublic && !localStorage.token) {
 return next('/login') 
}
next()
})
export default router
